package geppetto.phraseHMM.phraseExtraction.extractedphrase.data;

import geppetto.phraseHMM.phraseExtraction.extractedphrase.ExtractedPhrasePairData;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;


public class ScoreData extends ExtractedPhrasePairData{

	double score;
	
	public ScoreData(double score) {
		super();
		this.score = score;
	}	

	public double getScore() {
		return score;
	}


	public void setScore(double score) {
		this.score = score;
	}


	@Override
	public void merge(ArrayList<HashMap<String, ExtractedPhrasePairData>> generalData, ArrayList<ExtractedPhrasePairData> data) {
		if(data.contains(this)){
			data.remove(this);
		}
		
		for(ExtractedPhrasePairData d : data){
			if(d instanceof ScoreData){
				score += ((ScoreData)d).getScore();
			}
			else{
				System.err.println("trying to merge an instance of ScoreData to with another type of class");
				System.exit(-1);
			}
		}	
	}

	@Override
	public String toString() {
		return String.valueOf(score);
	}
	
	public static ScoreData parseString(String s) {
		return new ScoreData(Double.parseDouble(s));
	}

}
